/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InterfazProcesoLU.java
 *
 * Created on 23/11/2010, 10:31:43 AM
 */

package interfaz;

import javax.swing.JLabel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Kke
 */
public class InterfazProcesoLU extends javax.swing.JFrame {

    /** Creates new form InterfazProcesoLU */
    public InterfazProcesoLU() {
        initComponents();
        setLocationRelativeTo(null);
    }

    public JLabel getLabelStatus() {
        return LabelStatus;
    }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblL = new javax.swing.JLabel();
        lblU = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblL = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblU = new javax.swing.JTable();
        LabelStatus = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Matrices L U");

        lblL.setFont(new java.awt.Font("Verdana", 0, 36));
        lblL.setText("L");

        lblU.setFont(new java.awt.Font("Verdana", 0, 36));
        lblU.setText("U");

        tblL.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblL);

        tblU.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(tblU);

        LabelStatus.setText("jLabel1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(166, 166, 166)
                .addComponent(lblL, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 274, Short.MAX_VALUE)
                .addComponent(lblU, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(226, 226, 226))
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(LabelStatus)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(32, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addComponent(LabelStatus)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblU)
                    .addComponent(lblL))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(49, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new InterfazProcesoLU().setVisible(true);
            }
        });
    }

    public void imprimirMatrices() {
        int n = L.length;
        String[] namesL = new String[n], namesU = new String[n];
        for (int i = 0; i < n; i++) {
            namesL[i] = "L" + i;
            namesU[i] = "U" + i;
        }

        Double[][] newModelL = new Double[n][n], newModelU = new Double[n][n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                newModelL[i][j] = L[i][j];
                newModelU[i][j] = U[i][j];
            }
        }

        DefaultTableModel dtL = new DefaultTableModel(newModelL, namesL), dtU = new DefaultTableModel(newModelU, namesU);

        tblL.setModel(dtL);
        tblU.setModel(dtU);

        dtL.fireTableDataChanged();
        dtU.fireTableDataChanged();

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel LabelStatus;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblL;
    private javax.swing.JLabel lblU;
    private javax.swing.JTable tblL;
    private javax.swing.JTable tblU;
    // End of variables declaration//GEN-END:variables

    private double[][] L, U;

    public void setL(double[][] newL) {
        L = newL;
    }

    public void setU(double[][] newU) {
        U = newU;
    }

    public void setVisible(boolean val) {
        if (val)
            imprimirMatrices();
        super.setVisible(val);
    }

}


